package com.yc.healthy.controller;


import com.yc.healthy.entity.Result;
import com.yc.healthy.entity.User;
import com.yc.healthy.mapper.UserMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyl
 * @since 2023-03-08
 */
@Controller
@RequestMapping("/healthy/user")
public class UserController {

    @Resource
    UserMapper userMapper;

    @PostMapping("register")
    @ResponseBody
    public Result Register(@RequestParam("username") String username,
                           @RequestParam("password") String pwd,
                           @RequestParam("repwd") String repwd){
        if (username == null || username.trim().isEmpty()){
            return new Result(0,"请输入用户名",null);
        }
        if (pwd == null || pwd.trim().isEmpty()){
            return new Result(0,"请输入密码", null);
        }
        if (repwd == null || repwd.trim().isEmpty()){
            return new Result(0,"请确认密码", null);
        }
        if (!pwd.equals(repwd)){
            return new Result(0,"两次输入的密码不一致", null);
        }
        int register = userMapper.Register(username, pwd);
        return new Result(1,"注册成功",register);

    }

}

